#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QWebEngineView>
#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
#include "cJSON.h"
#include <QDebug>
#include <vector>
#include <QUrl>
#include <QElapsedTimer>
#include <QtMath>

#define MULTICHANNELS 1
//#define USE_REG_TABLE

#define PORT 5400

typedef struct{
    int length;
    int distance;
    bool isRecd;
}CameraData;

typedef struct{
    QUrl url;
    CameraData camData;
}SocketInfo;

typedef enum{
    SHOW_FIRST_WINDOW = 0,
    SHOW_SECOND_WINDOW,
    SHOW_BOTH_WINDOWS
}ShowMode;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void NewConnSlot();
    void disconnectedSlot();
    void ReadData();
    void on_radioButtonSecondCh_clicked();
    void on_radioButtonFirstCh_clicked();
    void on_radioButtonBothCh_clicked();
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
    QWebEngineView *view1, *view2;
    std::vector<SocketInfo> socketInfo_;
    QTcpServer *server;
    QList<QTcpSocket*> tcpClient;
    QTcpSocket *currentClient;
    ShowMode showMode_;

    void CloseAllView();
    void RefreshAllView();
    void ProcessData();
    void ForceFinishMeau();

protected:
    void resizeEvent(QResizeEvent *);

};

#endif // MAINWINDOW_H
